<?php
class Useradmin_Data_Addform {
	
	private $form;
	private $database;
	
	public function __construct(){
		$this->form = new Core_Driver_Firstform;
		$this->database = new Core_Driver_MysqlImproved;
	}
	
	public function getForm(){
		$addForm = $this->form->startForm(
			array(
			"id" => "addForm",
					"method" => "post",
					"action" => SERVER_ROOT . "?useradmin&page=added"
		)
		);
		$addForm .= $this->form->inputForm(
			array(
					
					"type" => "hidden",
					"value" => "hidden",
					"name" =>"hidden"
			
		), null
		);
		$addForm .= ADD_USER_MESSAGE;
		$addForm .= "<ul>";
		$addForm .= "<li>";
		$addForm .= $this->form->labelForm(
			array(
			"for" => "username"
		),
				ADD_USER_USERNAME,
				null
		);
		$addForm .= $this->form->inputForm(
			array(
			"id" => "username",
					"name" => "username",
					"type" => "text",
					"placeholder" => ADD_USER_USERNAME_PLACEHOLDER,
					"maxlength" => "255"
		),
			"required autofocus"
		);
		$addForm .= "</li>";
		$addForm .= "<li>";
		$addForm .= $this->form->labelForm(
			array(
			"for" => "realname"
		),
				ADD_USER_REALNAME,
				null
		);
		$addForm .= $this->form->inputForm(
			array(
			"id" => "realname",
					"name" => "realname",
					"type" => "text",
					"placeholder" => ADD_USER_REALNAME_PLACEHOLDER,
					"maxlength" => "255"
		),
				"required autofocus"
		);
		$addForm .= "<li>";
		$addForm .= "</li>";
		$addForm .= $this->form->labelForm(
			array(
					"for" => "email"
					),
				ADD_USER_EMAIL,
				null
		);
		$addForm .= $this->form->inputForm(
			array(
			"id" => "email",
					"name" => "email",
					"type" => "email",
					"placeholder" => ADD_USER_EMAIL_PLACEHOLDER,
					"maxlength" => "255"
		),
				"required autofocus"
		);
		$addForm .= "</li>";
		$addForm .= "<li>";
		$addForm .= $this->form->labelForm(
			array(
					"for" => "password"
		),
				ADD_USER_PASSWORD,
				null
		);
		$addForm .= $this->form->inputForm(
			array(
			"id" => "password",
					"name" => "password",
					"type" => "password",
					"placeholder" => ADD_USER_PASSWORD_PLACEHOLDER,
					"maxlength" => "255"
		),
				"required autofocus"
		);
		$addForm .= "</li>";
		$addForm .= "<li>";
		$addForm .= $this->form->labelForm(
			array(
				"for" => "retypePassword"
		),
				ADD_USER_RETYPE_PASSWORD,
				null
		);
		$addForm .= $this->form->inputForm(
			array(
			"id" => "retypePassword",
					"name" => "retypePassword",
					"placeholder" => ADD_USER_RETYPE_PASSWORD_PLACEHOLDER,
					"type" => "password",
					"maxlength" => "255"
		),
				"required autofocus"
		);
		$addForm .= "</li>";
		$addForm .= "<li>";
		$addForm .= $this->form->labelForm(
			array(
			"for" => "banned"
		),
				ADD_USER_ACTIVE,
				null
		);
		$addForm .= $this->form->selectForm(
			array(
			"id" => "banned",
					"name" => "banned"
		),
				"required",
				array(
			"0" => "(0) Active",
						"1" => "(1) No active"
		)
		);
		$addForm .= "</li>";
		$addForm .= "<li>";
		$accessLevels = $this->getAccessLevels();
		$addForm .= $this->form->labelForm(
			array(
			"for" => "accessLevel"
		),
				ADD_USER_ACCESS_LEVEL,
				null
		);
		$addForm .= $this->form->selectForm(
			array(
			"id" => "accessLevel",
					"name" => "accessLevel"
		),
				"required",
				$accessLevels
		);
		$addForm .= "</li>";
		$addForm .= "</ul>";
		$addForm .= '<div class = "buttons">';
		$addForm .= $this->form->inputForm(
			array(
					"id" => "submit",
				"name" => "submit",
				"type" => "submit",
				"value" => ADD_USER_BUTTON
					),
				null
		);
		$addForm .= "</div>";
		return $addForm;
	}
	
	private function getAccessLevels(){
		$this->database->connect();
		$this->database->prepare(
			"select * from privileges order by privileges_types"
		);
		$this->database->query();
		$accessLevels = array();
		while($accessData = $this->database->fetch('array')){
			$accessLevels[$accessData['privileges_types']] = "(".$accessData['privileges_types'].") ".$accessData['privileges_name'];
		}
		return $accessLevels;
	}
}